﻿using ConfExpert.Forms.Base;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Extensions;
using DevExpress.XtraEditors.Repository;
using DevExpress.XtraEditors.Controls;
using DevTeamIT;
using DevExpress.XtraGrid.Columns;

namespace ITaskManager.Forms
{
    public partial class FaturaLinesDuzenle : XForm
    {
        private int IT_FaturaLinesId;

        public FaturaLinesDuzenle()
        {
            InitializeComponent();
        }

        public FaturaLinesDuzenle(int IT_FaturaLinesId)
        {
            // TODO: Complete member initialization
            InitializeComponent();
            this.IT_FaturaLinesId = IT_FaturaLinesId;
        }

        private void FaturaLinesDuzenle_Load(object sender, EventArgs e)
        {
            this.Text = "Fatura Kalemini Düzenle";
            gvFaturaLinesDuzenle.Init("IT_GetFaturaDuzenle", IT_FaturaLinesId);
            btnKaydet.ItemClick += btnKaydet_ItemClick;
            gvFaturaLinesDuzenle.MakeColumnInvisible("IT_FaturaLinesId","IT_FaturaId");
            gvFaturaLinesDuzenle.SetCaptions("UrunAdi:Ürün","KullanimAmaci:Kullanım Amacı");


            GridColumn colUrun = gvFaturaLinesDuzenle.Columns["UrunAdi"];
            colUrun.ColumnEdit = GetIntellisensedRI(ExecuteDataTable("GetDistinctValues", "UrunAdi"));
            ((RepositoryItemGridLookUpEdit)colUrun.ColumnEdit).ProcessNewValue += ri_NewValue;

            gvFaturaLinesDuzenle.BestFitColumns();
        }

        void btnKaydet_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            gvFaturaLinesDuzenle.CloseEditor();
            gvFaturaLinesDuzenle.EndEdit();
            DataRow dr = gvFaturaLinesDuzenle.GetFocusedDataRow();


            string UrunAdi = dr["UrunAdi"].ToStr();
            string KullanimAmaci = dr["KullanimAmaci"].ToStr();
            int Adet = dr["Adet"].ToInt();
            decimal BirimFiyat = dr["BirimFiyat"].ToDecimal();

            ExecuteNonQuery("IT_UpdFaturaLinesRow", UrunAdi, KullanimAmaci, Adet, BirimFiyat, this.IT_FaturaLinesId);
            this.Close();
                
           
        }
    }
}
